package org.jeecg.modules.api.wlhy.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.wlhy.app.entity.AppVersion;
import org.jeecg.modules.wlhy.app.service.IAppVersionService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: app版本控制
 * @Author: jeecg-boot
 * @Date:   2020-12-23
 * @Version: V1.0
 */
@Api(tags="app版本控制")
@RestController
@RequestMapping("/app/appVersion")
@Slf4j
public class ApiAppController extends JeecgController<AppVersion, IAppVersionService> {
    @Autowired
    private IAppVersionService appVersionService;


    /**
     * 通过id查询
     *
     * @param
     * @return
     */
//    @AutoLog(value = "app版本控制-通过id查询")
    @ApiOperation(value="app版本控制-通过id查询", notes="app版本控制-通过id查询")
    @GetMapping(value = "/queryByVersion")
    public Result<?> queryByVersion(@RequestParam(name="version",required=true) String version,@RequestParam(name="type",required=true) String type) {

        AppVersion one = appVersionService.getOne(new LambdaQueryWrapper<AppVersion>()
                            .eq(AppVersion::getType, type)
                            .orderByDesc(AppVersion::getCreateTime)
                            .last("limit 1"));
        log.info("获取APP最新版本, 当前：{}，最新：{}，类型:{}", version, ObjectUtil.isEmpty(one) ? "" : one.getVersionCode(), type);
//        AppVersion one = appVersionService.getOne(
//                new QueryWrapper<AppVersion>()
//                        .gt("version_code",version)
////                        .eq("version_code",version)
//                        // TODO: 2020/12/25 0025    查询app版本小于当前版本
//                        .eq("type",type)
//        );

        return Result.OK(one);
    }



}
